<%--
  Created by IntelliJ IDEA.
  User: 田同学
  Date: 2021/12/28
  Time: 19:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>

<body>
    <div class="container" >
            <div style="width: 100%;height: 950px;border: #71daec solid;" >
                <div style="width: 100%;height: 5%;background-color: #71daec"><label style="color: #ffffff;margin: 8px" >主信息</label></div>
            <form id="form01" method="post">
                <!--主信息-->
                <div class="row" id="div01">
                <br>
                <div class="col-md-6 form-inline">
                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label for="PRODUCTNAME">产品名称：</label><input name="productName" type="text" id="PRODUCTNAME" required="true" maxlength="20" minlength="1"  style="width: 400px" class="form-control" placeholder="请输入产品名称" >
                </div>
                <div class="col-md-6 form-inline">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label for="FACTORYNAME">制造商：</label><input name="factoryName" id="FACTORYNAME" type="text" style="width: 400px" class="form-control" placeholder="请输入制造商" >
                </div>
                <br><br><br>
                <div class="row">
                    <div class="col-md-6 form-inline">
                       &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="FIRSTKINDID01">I&nbsp;级分类：</label><select id="FIRSTKINDID01" required="true" class="form-control "style="width: 300px">
                            <option value="">---请选择I级分类---</option>
                        </select>
                    </div>
                    <div class="col-md-6 form-inline">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="FIRSTKINDID02">II&nbsp;级分类：</label><select id="FIRSTKINDID02" required="true" class="form-control "style="width: 300px">
                        <option value="">---请选择II级分类---</option>
                    </select>
                    </div>
                 </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                           &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label for="FIRSTKINDID03">III&nbsp;级分类：</label><select id="FIRSTKINDID03" required="true" class="form-control "style="width: 300px">
                            <option value="">---请选择III级分类---</option>
                        </select>
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >产品简介：</label><input name="productNick" id="PRODUCT_NICK" type="text" class="form-control" placeholder="产品简介" style="width: 300px">
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label for="TYPE">用途类型：</label><select required="true" id="TYPE" class="form-control "style="width: 300px">
                            <option value="">---请选择用途类型---</option>
                            <option value="Y001-1">商品</option>
                            <option value="Y001-2">物料</option>
                        </select>
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >档次级别：</label><select id="PRODUCT_CLASS" class="form-control "style="width: 300px">
                            <option value="0">---请选择档次级别---</option>
                            <option value="D001-1">高档</option>
                            <option value="D001-2">中档</option>
                            <option value="D001-3">低档</option>
                        </select>
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >计量单位：</label><input name="personalUnit" type="text" class="form-control" placeholder="请输入计量单位" style="width: 300px">
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >计量值：</label><input name="personalValue" type="text" class="form-control" placeholder="请输入计量值" style="width: 300px">
                        </div>
                    </div>
                   <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >市场单价(元)：</label><input name="listPrice" id="provider_Group" type="number" class="form-control" maxlength="10" minlength="0" required="true"  placeholder="请输入市场单价" style="width: 300px">
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >计划成本单价：</label><input name="costPrice" id="cost_Price" type="number" class="form-control" required="true" maxlength="10" minlength="0"  placeholder="请输入计划成本单价" style="width: 300px">
                        </div>
                    </div>
                </div>
                <br>
                <div style="width: 100%;height: 5%;background-color: #71daec"><label style="color: #ffffff;margin: 8px" >辅助信息</label></div>
                <!--辅助信息-->
                <div class="row">
                    <br>
                    <div class="col-md-6 form-inline">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <label >保修期：</label><input name="warranty" type="text" style="width: 400px" class="form-control" placeholder="请输入保修日期" >
                    </div>
                    <div class="col-md-6 form-inline">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <label >替代品名称：</label><input name="twinName" type="text" style="width: 400px" class="form-control" placeholder="请输入替代品名称" >
                    </div>
                    <br><br><br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >替代品编号：</label><input name="twinId" type="text" style="width: 400px" class="form-control" placeholder="请输入替代品名称" >
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >生命周期(年)：</label><input name="lifecycle" type="text" style="width: 400px" class="form-control" placeholder="请输入生命周期日期" >
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >单位：</label><input name="amountUnit" type="text" class="form-control" placeholder="请输入单位" style="width: 300px">
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >产品经理：</label><select id="RESPONSIBLE_PERSON" class="form-control "style="width: 300px">
                            <option value="0">---请选择产品经理---</option>
                            <option value="哈皮">哈皮</option>
                            <option value="沟沟">沟沟</option>
                        </select>
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label style="float: left;line-height: 72px;position: relative;left: 60px">供应商集合：</label>
                            <textarea style="width: 300px;padding-bottom: 40px" name="providerGroup"></textarea>
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label style="float: left;line-height: 72px;position: relative;left: 54px">产品描述：</label>
                            <textarea style="width: 300px;padding-bottom: 40px" name="productDescribe"></textarea>
                        </select>
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6 form-inline">
                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >登记人：</label><input name="register" type="text" class="form-control" placeholder="请输入登记人姓名" style="width: 300px">
                        </div>
                        <div class="col-md-6 form-inline">
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <label >建档时间：</label><span   id="dateTime" class="form-control" disabled style="width: 300px"></span>
                        </div>
                    </div>


                </div>
                <br><br><br>
                <div class="row">
                    <div class="col-md-9" style="position: relative;left: 150px">
                        <input type="submit" id="commit"  class="btn btn-success btn-block" value="提交" >
                    </div>
                    <br><br><br>
                    <div class="col-md-3" style="position: relative;left: 440px">
                        <input type="reset" class="btn  btn-danger btn-block" value="清空"><br>
                    </div>
                </div>
            </form>
        </div>
    </div>

<script>


    //判断是否先择下拉框
   // $("#commit").blur(function () {
   //         $("#div01 option:selected").each( function () {
   //      if($(this).val()=="0"){
   //         // alert($(this).parent().prev().text()+"未选择")
   //          $("#commit").attr("disabled","disabled")
   //      }else {
   //          $("#commit").attr("disabled","")
   //      }
   //  })
   //
   // })
    //创建假数据下拉框值
    // arr01=[{FIRST_KIND_ID:1,FIRST_KIND_NAME:"电子"}],
    // arr02=[{FIRST_KIND_ID:2,FIRST_KIND_NAME:"计算机"}],
    // arr03=[{FIRST_KIND_ID:3,FIRST_KIND_NAME:"服务器"}]

    //一进来获取当前时间
        $(document).ready(function () {
            var starDate =new Date();
            //window.alert(starDate.pattern("yyyy-MM-dd- hh:mm:ss"))
            $("#dateTime").text(starDate.getFullYear()
                +"-"+starDate.getMonth()+1
                +"-"+starDate.getDate()
                +" "+starDate.getHours()
                +":"+starDate.getMinutes()
                +":"+starDate.getSeconds()
            )
        })



    inln01(0)
        //获取下拉框值
        function inln01(pId){
            var pId={pId:pId};
            $.get("${pageContext.request.contextPath}/queryPull.action",
                pId,
                function (data) {
                    console.log(data)
                    //循环
                    $(data).each(function (index,item) {
                        var option=$("<option value='"+item.kindId+""+item.id+"'>"+item.kindName+"</option>")
                        $("#FIRSTKINDID01").append(option)

                    })
                    $("#FIRSTKINDID01").blur(function () {
                        $("#FIRSTKINDID02>option:gt(0)").remove()
                        $("#FIRSTKINDID03>option:gt(0)").remove()
                        var fir=$("#FIRSTKINDID01").val()
                        inln02(fir.substring(2),fir.substring(0,2))
                    })
                }),'json'
        }


    //第二个下拉框
    function inln02(pId,kindId){
        var dco={pId:pId,kindId:kindId};
        $.get("${pageContext.request.contextPath}/queryPull.action",
            dco,
            function (data) {
                console.log(data)
                //循环
                    $("#FIRSTKINDID02>option:gt(0)").remove()
                    $(data).each(function (index, item) {
                            var option = $("<option value='"+item.kindId+""+item.id+"'>" + item.kindName + "</option>")
                            $("#FIRSTKINDID02").append(option)
                    })
                $("#FIRSTKINDID02").blur(function () {
                    var fir=$("#FIRSTKINDID02").val()
                    inln03(fir.substring(2),fir.substring(0,2))
                })

            }),'json'
    }

    //第三个下拉框
    function inln03(pId,kindId){
        var dco={pId:pId,kindId:kindId};
        $.get("${pageContext.request.contextPath}/queryPull.action",
            dco,
            function (data) {
                console.log(data)
                //循环
                $("#FIRSTKINDID03>option:gt(0)").remove()
                $(data).each(function (index, item) {
                    var option = $("<option value='"+item.kindId+""+item.id+"'>" + item.kindName + "</option>")
                    $("#FIRSTKINDID03").append(option)
                })

            }),'json'
    }

    //提交数据
    /*$("#commit").click(function () {

    })*/


$(function () {
    var param01= {
        messages: {
            PRODUCTNAME: {
                "required": "请输入产品名称",
                "minlength": "最少输入1位"
            },

            provider_Group: {
                "required": "请输入价格",
                "minlength": "价格不能少于1位"
            },
            cost_Price:{
                "required": "请输入价格",
                "minlength": "价格不能少于1位"
            },
            FIRSTKINDID01:{
                "required": "请选择"
            },
            FIRSTKINDID02:{
                "required": "请选择"
            },
            FIRSTKINDID03:{
                "required": "请选择"
            },
            TYPE:{
                "required": "请选择"
            }
        },
        submitHandler: function (form) {
            //需要组装数据
            var I=$("#FIRSTKINDID01").val();
            var II=$("#FIRSTKINDID02").val();
            var III=$("#FIRSTKINDID03").val();
           var param02 = {
                url:"${pageContext.request.contextPath}/addbydfile.action",
                data:{
                    firstKindId:I.substring(0,2),
                    secondKindId:II.substring(0,2),
                    thirdKindId:III.substring(0,2),
                    firstKindName:$("#FIRSTKINDID01 option:selected").text(),
                    secondKindName:$("#FIRSTKINDID02 option:selected").text(),
                    thirdKindName:$("#FIRSTKINDID03 option:selected").text(),
                    type:$("#TYPE").val(),
                    productClass:$("#PRODUCT_CLASS").val(),
                    responsiblePerson:$("#RESPONSIBLE_PERSON").val(),
                    registerTime:$("#dateTime").text(),
                    checkTag:"S001-0"
                },
                dataType:'json',
                success:function (data) {
                        alert(data.msg)
                    //当添加成功后重置所以数据
                    if (data.code==1){
                        $(":input","#form01").resetForm();

                    }
              }
            }
            $("#form01").ajaxSubmit(param02);
        }
    }
    $("#form01").validate(param01);
})


</script>
</body>
</html>
